<?php
require_once '../sub/init.php';
require_once 'chkUadm.php';
if(!CRM_ADM)exit(noauth('只有CRM超级管理员才可以设置哦'));
require_once ZEAI.'cache/config_crm.php';
if($submitok=='clearwh'){
	$db->query("DELETE FROM ".__TBL_TALK__." WHERE uid IN (SELECT id FROM ".__TBL_USER__." WHERE crm_ugrade=0 AND crm_flag<3)");
	AddLog('【CRM】->一键清空【红娘外呼跟进记录】');
	json_exit(array('flag'=>1,'msg'=>'操作成功'));
}elseif($submitok=='clearsq'){
	if(empty($sDATE1) || empty($sDATE2))json_exit(array('flag'=>0,'msg'=>'请选择【售前分配时间】区间'));
	$SQL  = " AND ( date_format(from_unixtime(hntime),'%Y-%m-%d') >= '$sDATE1' )  AND ( date_format(from_unixtime(hntime),'%Y-%m-%d') <= '$sDATE2' )    ";
	
	gyl_debug("UPDATE ".__TBL_USER__." SET hnid=0,hnname='',hntime=0 WHERE hnid>0 AND crm_ugrade=0 AND crm_flag<3".$SQL);
	
	$db->query("UPDATE ".__TBL_USER__." SET hnid=0,hnname='',hntime=0 WHERE hnid>0 AND crm_ugrade=0 AND crm_flag<3".$SQL);
	AddLog('【CRM】->一键清空【客户售前红娘归属】');
	json_exit(array('flag'=>1,'msg'=>'操作成功'));
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="<?php echo HOST;?>/res/www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="css/main.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css">
</head>
<body class="body">
<form id="W_W_W_Z_E__A_I__C_N__FORM">
<table class="table size2 W90_" style="margin:20px 0 100px 20px">
	<tr><th colspan="2" align="center"><b class="S18">CRM设置</b></th></tr>
	<tr>
		<td class="tdL">坠海倒计时</td>
		<td class="tdR">
        
<!--        认领坠海 <input name="sea_adm_day" type="text" class="W50 FVerdana" maxlength="5" value="<?php echo $_CRM['sea_adm_day'];?>"> 天　
        <div class="tips2"><img src="images/!.png" width="14" height="14" valign="middle"> <font class="S12 C999 ">此触发机制只对已认领售前客户有效：红娘认领后，超过此天数客户没有《新跟进＆新外呼＆新牵线＆新约见》记录，名下客户将被自动坠入公海资源，客户所属门店、认领红娘、售前红娘、售后红娘、归属将全部置空（记录坠海日志），其它门店红娘可以重新认领</font><br><font class="Cf00">《请慎用，无特殊情况推荐关闭，填0为关闭此功能》</font></div><br>
-->        
        
<input name="sea_hn_day" type="text" class="W50 FVerdana" maxlength="8" value="<?php echo $_CRM['sea_hn_day'];?>"> 天售前坠海 
　　　　　最后 <input name="sea_hn_day_tip" type="text" class="W50 FVerdana" maxlength="8" value="<?php echo $_CRM['sea_hn_day_tip'];?>"> 天提醒<span class="tips">(将在CRM《待办首页》《客户管理》《售前客户》客户列表标注提醒，填0不提醒)</span>
<div class="tips2"><img src="images/!.png" width="14" height="14" valign="middle"> 此触发机制只对售前客户和被分配的售前红娘有效：售前红娘被分配后，超过此天数名下客户没有《新跟进＆新外呼＆新牵线＆新约见》记录，自动将名下客户售前红娘归属置空（记录坠海日志），店长或管理员可以重新分配售前红娘<br><font class="Cf00">《无特殊情况推荐关闭，填0为关闭此功能》</font></div><br>

<input name="sea_hn2_day" type="text" class="W50 FVerdana" maxlength="8" value="<?php echo $_CRM['sea_hn2_day'];?>"> 天售后坠海
　　　　　最后 <input name="sea_hn2_day_tip" type="text" class="W50 FVerdana" maxlength="8" value="<?php echo $_CRM['sea_hn2_day_tip'];?>"> 天提醒<span class="tips">(将在CRM《待办首页》《客户管理》《售后客户》客户列表标注提醒，填0不提醒)</span>

<div class="tips2"><img src="images/!.png" width="14" height="14" valign="middle"> 此触发机制只对售后客户和被分配的售后红娘有效：售后红娘被分配后，超过此天数名下客户没有《新跟进＆新外呼＆新牵线＆新约见》记录，自动将名下客户售后红娘归属置空（记录坠海日志），店长或管理员可以重新分配售后红娘<br><font class="Cf00">《无特殊情况推荐关闭，填0为关闭此功能》</font></div>

        
        </td>
	</tr>
	<tr>
		<td class="tdL">一键清空售前</td>
		<td class="tdR">
        	当前售前归属：<?php echo $db->COUNT(__TBL_USER__,"hnid>0 AND crm_ugrade=0 AND crm_flag<3");?>人<br>
            售前分配时间：
            <input placeholder="起始日期" name="sDATE1" id="sDATE1" type="text"  class="input size2 W100" value="<?php echo (empty($sDATE1))?'':$sDATE1; ?>" size="10" maxlength="10" autocomplete="off">
            <b>～</b> 
            <input placeholder="结束日期" name="sDATE2" id="sDATE2" type="text"  class="input size2 W100" value="<?php echo (empty($sDATE2))?'':$sDATE2; ?>" size="10" maxlength="10" autocomplete="off">
        	<button type="button" class="btn size2 ico" id="clearsq">&#xe6c7; 清空-客户售前红娘归属</button><br><span class="tips2"><img src="images/!.png" width="14" height="14" valign="middle"> 此操作只清空全部客户的【售前红娘归属】(售后客户和服务成功客户不计入在内)，清空后可以重新分配售前，认领和售后归属不变<font class="Cf00">　《请谨慎操作，清空后将无法恢复》</font></span>
        </td>
	</tr>
    
	<tr>
		<td class="tdL">一键清空外呼</td>
		<td class="tdR">
            当前外呼记录：<?php
			$rtt = $db->query("SELECT COUNT(*) FROM ".__TBL_USER__." U,".__TBL_TALK__." T WHERE U.id=T.uid AND U.crm_ugrade=0 AND U.crm_flag<3");
			$roww = $db->fetch_array($rtt);
			echo $roww[0];
			?>条<br>
        	<button type="button" class="btn size2 ico" id="clearwh">&#xe6c7; 清空-红娘外呼跟进记录</button>　<span class="tips2"><img src="images/!.png" width="14" height="14" valign="middle"> 此操作将清空全部红娘的【外呼跟进记录】(售后客户和服务成功客户不计入在内)，清空后相关用户将自动进入外呼公海，销售可以重新拔打<font class="Cf00">　《请谨慎操作，清空后将无法恢复》</font></span>
        </td>
	</tr>    
    
</table>
<input name="submitok" type="hidden" value="cache_crm_set">
<input name="uu" type="hidden" value="<?php echo $session_uid;?>">
<input name="pp" type="hidden" value="<?php echo $session_pwd;?>">
</form>
<div class="savebtnbox"><button type="button" id="save" class="btn size3">确定并保存</button></div>
<script>
save.onclick = function(){
	zeai.ajax({url:'<?php echo HOST;?>/sub/cache'+zeai.extname,form:W_W_W_Z_E__A_I__C_N__FORM},function(e){var rs=zeai.jsoneval(e);
		zeai.msg(0);zeai.msg(rs.msg);
		if (rs.flag == 1){setTimeout(function(){location.reload(true);},1000);}
	});
}
clearsq.onclick = function(){
	zeai.confirm('<b class="S18">确定清空【客户售前红娘归属】么？</b><br><font class="Cf00">《请谨慎操作，清空后将无法恢复》</font>',function(){
		zeai.ajax({url:'crm_set.php?submitok=clearsq',data:{sDATE1:sDATE1.value,sDATE2:sDATE2.value}},function(e){var rs=zeai.jsoneval(e);
			zeai.msg(0);zeai.msg(rs.msg);
			if (rs.flag == 1){setTimeout(function(){location.reload(true);},1000);}
		});
	});
}
clearwh.onclick = function(){
	zeai.confirm('<b class="S18">确定清空【红娘外呼跟进记录】么？</b><br><font class="Cf00">《请谨慎操作，清空后将无法恢复》</font>',function(){
		zeai.ajax({url:'crm_set.php?submitok=clearwh'},function(e){var rs=zeai.jsoneval(e);
			zeai.msg(0);zeai.msg(rs.msg);
			if (rs.flag == 1){setTimeout(function(){location.reload(true);},1000);}
		});
	});
}
</script>
<script src="laydate/laydate.js"></script><script>lay('#version').html('-v'+ laydate.v);
laydate.render({elem: '#sDATE1'});
laydate.render({elem: '#sDATE2'});
</script>
<?php
require_once 'bottomadm.php';?>